package com.eleven.trades.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.eleven.trades.entity.Account;
import com.eleven.trades.vo.AccountBalance;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author linhaizeng
 */
public interface AccountMapper extends BaseMapper<Account> {

    /**
     * 查询账户信息
     * @param accountId
     * @return
     */
    @Select("select * from account where account_id=#{accountId}")
    Account selectByPrimaryKey(String accountId);

    /**
     * 根据账户id查询用户名
     * @param id
     * @return
     */
    @Select("select user_name from user a join account ac on a.user_id = ac.user_id where account_id = #{id}")
    String selectName(@Param("id") String id);

    /**
     * 更新余额
     * @param account
     * @param balance
     */
    @Update("update account set account_balance = #{balance} where account_id=#{account}")
    public void updateBalance(String account, Double balance);

    /**
     * 查询账号与余额
     * @param userId
     * @return
     */
    @Select("select account_id,account_balance from account where user_id = #{userId}")
    @Results({
            @Result(property = "accountId",column = "account_id"),
            @Result(property = "accountBalance",column = "account_balance")
    })
    List<AccountBalance> selectByAccountId(Integer userId);

    /**
     * 查询交易密码
     * @param accountId
     * @return
     */
    @Select("select pay_password from account where account_id = #{accountId}")
    String selectPPassword(String accountId);
}